var someFun = {
	//判断两个字符串中相同和不同的内容
	getDifferent(str1, str2) {
		str1 = str1.split('&')
		str2 = str2.split('&')
		let retData = [];
		str1.map((item, i) => {
			str2.map((info, index) => {
				if (info == item) {
					retData.push({
						item: info
					})
				}
			})
		})
		console.log('相同部分内容：', retData)
		if (retData.length == str1.length) {
			console.log('长度相同')
		} else {
			const res = str1.filter(i1 => {
				return !retData.find(i2 => i1 == i2)
			})
			console.log('两个数据中不同的部分：', res)
		}
	},
	//字符串转成utf8
	str2utf8(str) {
		return String.fromCharCode(str)
	},
	// 字符串转为uncode编码
	charToUnicode(str) {
		let temp;
		let i = 0;
		let r = '';

		for (let val of str) {
			temp = val.codePointAt(0).toString(16);
			while (temp.length < 4)
				temp = '0' + temp;
			r += '\\u' + temp;
		};
		return r;
	},
	//unicode为1个接收数据，串口收到的字符编码放在该数组中 
	UnicodeToUtf8(unicode) {
		var uchar;
		var utf8str = "";
		var i;
		for (i = 0; i < unicode.length; i += 2) {
			uchar = (unicode[i] << 8) | unicode[i + 1]; //UNICODE为2字节编码，一次读入2个字节 
			utf8str = utf8str + String.fromCharCode(uchar); //使用String.fromCharCode强制转换 
		}
		return utf8str;
	},
	// 将字符串格式化为UTF8编码的字节
	writeUTF(str, isGetBytes) {
		var back = [];
		var byteSize = 0;
		for (var i = 0; i < str.length; i++) {
			var code = str.charCodeAt(i);
			if (0x00 <= code && code <= 0x7f) {
				byteSize += 1;
				back.push(code);
			} else if (0x80 <= code && code <= 0x7ff) {
				byteSize += 2;
				back.push((192 | (31 & (code >> 6))));
				back.push((128 | (63 & code)))
			} else if ((0x800 <= code && code <= 0xd7ff) ||
				(0xe000 <= code && code <= 0xffff)) {
				byteSize += 3;
				back.push((224 | (15 & (code >> 12))));
				back.push((128 | (63 & (code >> 6))));
				back.push((128 | (63 & code)))
			}
			// code = back.map(item => '%'+item.toString(16)).join('')
		}
		for (i = 0; i < back.length; i++) {
			back[i] &= 0xff;
		}
		if (isGetBytes) {
			return back
		}
		if (byteSize <= 0xff) {
			// back = back.map(item => '%' + item.toString(16)).join('')
			return back;
		} else {
			// back = back.map(item => '%' + item.toString(16)).join('')
			return [byteSize >> 8, byteSize & 0xff].concat(back);
		}
	},
}
module.exports = {
	someFun: someFun
}
